package com.lengyu.iottransfer.gateway.influxdb;

import com.influxdb.LogLevel;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "influx2")
public class InfluxdbConfig {

    private static final Logger logger = LoggerFactory.getLogger(InfluxdbConfig.class);

    private final String url = "http://172.2.0.27:8086/";
    private String token = "rk3sU4LO_8G10RE7NIFWjrLldOLyvmkmJNNBCFEFDyc5Q0l5V35y1qktj5DiNHxnurNFCVfQb1lihw2C-e-20g==";

    @Bean
    public InfluxDBClient influxDBClient(){
        InfluxDBClient influxDBClient = InfluxDBClientFactory.create(url,token.toCharArray());
        //日志级别可用可不用
        influxDBClient.setLogLevel(LogLevel.BASIC);
        if (influxDBClient.ping()){
            logger.info("InfluxDB时序数据库2.x---------------------------------------------连接成功!");
        }else {
            logger.info("InfluxDB时序数据库2.x---------------------------------------------连接失败!");
        }
        return influxDBClient;
    }

//    public void setUrl(String url) {
//        this.url = url;
//    }
//
//    public void setToken(String token) {
//        this.token = token;
//    }
//
//    public void setOrg(String org) {
//        this.org = org;
//    }
//
//    public void setBucket(String bucket) {
//        this.bucket = bucket;
//    }
}

